//
//  RAUtil.m
//  RAFSUManagement
//
//  Created by Piccolo on 21/03/2018.
//  Copyright © 2018 Rayonics. All rights reserved.
//

#import "RAUtil.h"
#import <sys/sysctl.h>

@implementation RAUtil

+ (NSString *)deviceVersion {
    return [[UIDevice currentDevice] systemVersion];
}

+ (NSString *)identityVersion {
    return [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
}

+ (void)showAlertViewWithPermissionType:(NSRAPermissionType)permissionType viewController:(UIViewController *)vc{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        SCLAlertView *alertView = [SCLAlertView new];
        NSString *alertTitle = @"";
        NSString *alertDetail = @"";
        switch (permissionType) {
            case NSRAPermissionTypeCamera:
                [alertView addButton:[self getSingleKeyStr:@"TEXT_SET"] validationBlock:^BOOL{
                    return YES;
                } actionBlock:^{
                    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
                }];
                alertTitle = [self getSingleKeyStr:@"TEXT_CAMERA_PERMISSION_DENIED"];
                alertDetail = [self getSingleKeyStr:@"TEXT_OPEN_CAMERA_PERMISSION"];
                break;
            case NSRAPermissionTypeBlueTooth:
                [alertView addButton:[self getSingleKeyStr:@"TEXT_SET"] validationBlock:^BOOL{
                    return YES;
                } actionBlock:^{
                    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"prefs:root=Bluetooth"]]) {
                        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Bluetooth"]];
                    } else {
                        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=Bluetooth"]];//prefs:root=General&path=Bluetooth
                        //                    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];//prefs:root=General&path=Bluetooth
                    }
                }];
                
                alertTitle = [self getSingleKeyStr:@"TEXT_BLUETOOTH_PERMISSION_DENIED"];
                alertDetail = [self getSingleKeyStr:@"TEXT_OPEN_BLUETOOTH_PERMISSION"];
                if ([[self deviceVersion] integerValue] == 11) {
                    alertDetail = [self getSingleKeyStr:@"TEXT_OPEN_BLUETOOTH_PERMISSION_IOS11"];
                }
                
                break;
            case NSRAPermissionTypeLocation:
                [alertView addButton:[self getSingleKeyStr:@"TEXT_SET"] validationBlock:^BOOL{
                    return YES;
                } actionBlock:^{
                    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]]) {
                        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]];
                    } else {
                        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=Privacy&path=LOCATION"]];//prefs:root=General&path=Bluetooth
                        //                    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];//prefs:root=General&path=Bluetooth
                    }
                }];
                
                alertTitle = [self getSingleKeyStr:@"TEXT_LOCATION_PERMISSION_DENIED"];
                alertDetail = [self getSingleKeyStr:@"TEXT_OPEN_LOCATION_PERMISSION"];
                break;
                
            default:
                break;
        }
        [alertView showError:vc title:alertTitle subTitle:alertDetail closeButtonTitle:[self getSingleKeyStr:@"TEXT_CANCEL"] duration:0];
    });
    
}

+ (NSString *)getSingleKeyStr:(NSString *)str {
    return NSLocalizedString(str, nil);
}

+ (UIViewController*) getTopMostViewController {
    UIWindow *window = [[UIApplication sharedApplication] keyWindow];
    if (window.windowLevel != UIWindowLevelNormal) {
        NSArray *windows = [[UIApplication sharedApplication] windows];
        for(window in windows) {
            if (window.windowLevel == UIWindowLevelNormal) {
                break;
            }
        }
    }
    
    for (UIView *subView in [window subviews])
    {
        UIResponder *responder = [subView nextResponder];
        
        //added this block of code for iOS 8 which puts a UITransitionView in between the UIWindow and the UILayoutContainerView
        if ([responder isEqual:window])
        {
            //this is a UITransitionView
            if ([[subView subviews] count])
            {
                UIView *subSubView = [subView subviews][0]; //this should be the UILayoutContainerView
                responder = [subSubView nextResponder];
            }
        }
        
        if([responder isKindOfClass:[UIViewController class]]) {
            return [self topViewController: (UIViewController *) responder];
        }
    }
    
    return nil;
}

+ (UIViewController *) topViewController: (UIViewController *) controller {
    BOOL isPresenting = NO;
    do {
        // this path is called only on iOS 6+, so -presentedViewController is fine here.
        UIViewController *presented = [controller presentedViewController];
        isPresenting = presented != nil;
        if(presented != nil) {
            controller = presented;
        }
        
    } while (isPresenting);
    
    return controller;
}

+ (BOOL)checkStringExist:(NSString *)str {
    if (!str) {
        return NO;
    } else if ([str isEqualToString:@""]) {
        return NO;
    } else {
        return YES;
    }
}

+ (BOOL)checkString:(NSString *)parentStr containSubString:(NSString *)subStr{
    if (!parentStr) {
        return NO;
    }
    NSString *string = parentStr;
    return [string rangeOfString:subStr].location != NSNotFound;
}

+ (BOOL)delegateExist:(id)delegate delegate:(Protocol *)protocol selector:(SEL)aSelector {
    BOOL bool1 = delegate;
    BOOL bool2 = [delegate conformsToProtocol:protocol];
    BOOL bool3 = [delegate respondsToSelector:aSelector];
    
    NSLog(@"@221%d%d%d",bool1, bool2, bool3);
    return delegate && [delegate conformsToProtocol:protocol] && [delegate respondsToSelector:aSelector];
}

+ (void)showAlertWithMessage:(NSString *)message alertType:(NSRAAlertType)alertType {
    
    [self showAlertWithMessage:message alertType:alertType progress:0.f];
}

+ (void)showAlertWithMessage:(NSString *)message alertType:(NSRAAlertType)alertType progress:(CGFloat)progress {

    dispatch_async(dispatch_get_main_queue(), ^{
        switch (alertType) {
            case NSRAAlertTypeSuccessful:
                [SVProgressHUD showSuccessWithStatus:message];
                break;
            case NSRAAlertTypeInfo:
                [SVProgressHUD showInfoWithStatus:message];
                break;
            case NSRAAlertTypeError:
                [SVProgressHUD showErrorWithStatus:message];
                break;
            case NSRAAlertTypeProgress:
                [SVProgressHUD showProgress:progress status:message];
                break;
            case NSRAAlertTypeLoading:
                [SVProgressHUD showWithStatus:message];
                break;
            default:
                break;
        }
    });
    
}

+ (DGActivityIndicatorView *)newIndicatorWithTarget:(UIViewController *)vc centerPoint:(CGPoint)point{
    DGActivityIndicatorView *indicator = [[DGActivityIndicatorView alloc] initWithType:DGActivityIndicatorAnimationTypeLineScale tintColor:[UIColor blackColor]];
    indicator.frame = CGRectMake(0, 0, 20.f, 20.f);
    indicator.center = point;
    [indicator startAnimating];
    indicator.alpha = .5f;
    return indicator;
}

+ (void)setIndicator:(DGActivityIndicatorView *) indicator hidden:(BOOL)hidden target:(UIViewController *)target aboveSubView:(UIView *)view{
    
    if ([self isAtMainThread]) {
        [self setSafeIndicator:indicator hidden:hidden target:target aboveSubView:view];
    } else {
        dispatch_async(dispatch_get_main_queue(), ^{
            [self setSafeIndicator:indicator hidden:hidden target:target aboveSubView:view];
        });
    }
}

+ (BOOL)isAtMainThread {
    if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(dispatch_get_main_queue())) == 0) {
        // do something  in main thread
        return YES;
    } else {
        // do something in other thread
        return NO;
    }
}

+ (void)setSafeIndicator:(DGActivityIndicatorView *) indicator hidden:(BOOL)hidden target:(UIViewController *)target aboveSubView:(UIView *)view {
    if (hidden) {
        [indicator removeFromSuperview];
    }else{
        indicator.hidden = NO;
        if (![target.view.subviews containsObject:indicator]) {
            if (view) {
                [target.view insertSubview:indicator aboveSubview:view];
            }else{
                [target.view addSubview:indicator];
            }
        }
    }
}

+ (BOOL)isExistDic:(NSDictionary *)dic key:(NSString *)key{
    
    if (![dic isKindOfClass:[NSDictionary class]] && ![dic isKindOfClass:[NSMutableDictionary class]]) {
        return NO;
    }
    
    if (dic && ![dic isEqual:[NSNull null]] && dic.allKeys.count != 0) {
        if (key) {
            if ([dic.allKeys containsObject:key]) {
                if (![dic[key] isEqual:[NSNull null]]){
                    if ([dic[key] isKindOfClass:[NSArray class]]) {
                        return [dic[key] count];
                    } else {
                        return YES;
                    }
                } else {
                    return NO;
                }
            } else {
                return NO;
            }
        } else {
            return YES;
        }
    } else {
        return NO;
    }
    
    
}

+ (BOOL)isNotEmptyArray:(NSArray *)array {
    if (!array) {
        return NO;
    } else if ([array isEqual:[NSNull null]]) {
        return NO;
    } else if (array.count == 0) {
        return NO;
    } else {
        return YES;
    }
    
}

+ (NSString *)noNullString:(NSString *)string {
    if ([self checkStringExist:string]) {
        return string;
    } else {
        return @"";
    }
}

+ (void)pushViewController:(UIViewController *)localViewController toTargetViewController:(UIViewController *)targetViewController animated:(BOOL)animated {
    
    if (targetViewController) {
        NSMutableArray *allViewControllers = [NSMutableArray arrayWithArray:[localViewController.navigationController viewControllers]];
        if ([allViewControllers containsObject:targetViewController]) {
            [localViewController.navigationController popToViewController:targetViewController animated:animated];
            return;
        }
        
        @try {
            [localViewController.navigationController pushViewController:targetViewController animated:animated];
        } @catch (NSException * ex) {
            //“Pushing the same view controller instance more than once is not supported”
            //NSInvalidArgumentException
            NSLog(@"Exception: [%@]:%@",[ex  class], ex );
            NSLog(@"ex.name:'%@'", ex.name);
            NSLog(@"ex.reason:'%@'", ex.reason);
            //Full error includes class pointer address so only care if it starts with this error
            NSRange range = [ex.reason rangeOfString:@"Pushing the same view controller instance more than once is not supported"];
            
            if ([ex.name isEqualToString:@"NSInvalidArgumentException"] &&
                range.location != NSNotFound) {
                //view controller already exists in the stack - just pop back to it
                [localViewController.navigationController popToViewController:targetViewController animated:animated];
            } else {
                NSLog(@"ERROR:UNHANDLED EXCEPTION TYPE:%@", ex);
            }
        } @finally {
            NSLog(@"@2037finally");
        }
    } else {
        NSLog(@"ERROR:pushViewController: viewController is nil");
    }
}

+ (void)removeBtnTarget:(UIButton *)btn {
    [btn removeTarget:nil
               action:NULL
     forControlEvents:UIControlEventAllEvents];
}

+ (void)setDownView:(UIView *)downView aboveView:(UIView *)upView spacing:(CGFloat)spacing {
    CGRect downViewFrame = downView.frame;
    CGRect upViewFrame = upView.frame;
    downViewFrame.origin.y = CGRectGetMaxY(upViewFrame) + spacing;
    downView.frame = downViewFrame;
}

+ (void)setSuperView:(UIView *)superView fromLastSubView:(UIView *)lastSubView spacing:(CGFloat)spacing {
    NSLog(@"@1693:%@", NSStringFromClass(superView.class));
    CGRect superViewFrame = superView.frame;
    CGRect lastSubViewFrame = lastSubView.frame;
    //    if (CGRectGetMaxY(lastSubViewFrame) + spacing > superViewFrame.size.height) {
    superViewFrame.size.height = CGRectGetMaxY(lastSubViewFrame) + spacing;
    //    }
    superView.frame = superViewFrame;
}

+ (void)setRightView:(UIView *)rightView nextToView:(UIView *)leftView sameFrame:(BOOL)sameFrame spacing:(CGFloat)spacing {
    
    CGRect rightViewFrame = rightView.frame;
    CGRect leftViewFrame = leftView.frame;
    if (sameFrame) {
        rightViewFrame = leftViewFrame;
    }
    rightViewFrame.origin.x = CGRectGetMaxX(leftViewFrame) + spacing;
    rightView.frame = rightViewFrame;
}

+ (NSString *)platformString
{
    size_t size;
    sysctlbyname("hw.machine", NULL, &size, NULL, 0);
    char *machine = malloc(size);
    sysctlbyname("hw.machine", machine, &size, NULL, 0);
    NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
    free(machine);
    
    // Created from this thread: https://gist.github.com/Jaybles/1323251
    
    // Apple TV
    if ([platform isEqualToString:@"AppleTV2,1"])   return @"Apple TV 2G";
    if ([platform isEqualToString:@"AppleTV3,1"])   return @"Apple TV 3G";
    if ([platform isEqualToString:@"AppleTV3,2"])   return @"Apple TV 3G";
    if ([platform isEqualToString:@"AppleTV5,3"])   return @"Apple TV 4G";
    
    // Apple Watch
    if ([platform isEqualToString:@"Watch1,1"])     return @"Apple Watch";
    if ([platform isEqualToString:@"Watch1,2"])     return @"Apple Watch";
    
    // iPhone
    if ([platform isEqualToString:@"iPhone1,1"])    return @"iPhone 2G";
    if ([platform isEqualToString:@"iPhone1,2"])    return @"iPhone 3G";
    if ([platform isEqualToString:@"iPhone2,1"])    return @"iPhone 3GS";
    if ([platform isEqualToString:@"iPhone3,1"])    return @"iPhone 4 (GSM)";
    if ([platform isEqualToString:@"iPhone3,2"])    return @"iPhone 4 (GSM/2012)";
    if ([platform isEqualToString:@"iPhone3,3"])    return @"iPhone 4 (CDMA)";
    if ([platform isEqualToString:@"iPhone4,1"])    return @"iPhone 4S";
    if ([platform isEqualToString:@"iPhone5,1"])    return @"iPhone 5 (GSM)";
    if ([platform isEqualToString:@"iPhone5,2"])    return @"iPhone 5 (Global)";
    if ([platform isEqualToString:@"iPhone5,3"])    return @"iPhone 5c (GSM)";
    if ([platform isEqualToString:@"iPhone5,4"])    return @"iPhone 5c (Global)";
    if ([platform isEqualToString:@"iPhone6,1"])    return @"iPhone 5s (GSM)";
    if ([platform isEqualToString:@"iPhone6,2"])    return @"iPhone 5s (Global)";
    if ([platform isEqualToString:@"iPhone7,2"])    return @"iPhone 6";
    if ([platform isEqualToString:@"iPhone7,1"])    return @"iPhone 6 Plus";
    if ([platform isEqualToString:@"iPhone8,1"])    return @"iPhone 6s";
    if ([platform isEqualToString:@"iPhone8,2"])    return @"iPhone 6s Plus";
    if ([platform isEqualToString:@"iPhone8,4"])    return @"iPhone SE";
    if ([platform isEqualToString:@"iPhone9,1"])    return @"iPhone 7 (Global)";
    if ([platform isEqualToString:@"iPhone9,2"])    return @"iPhone 7 Plus (Global)";
    if ([platform isEqualToString:@"iPhone9,3"])    return @"iPhone 7 (GSM)";
    if ([platform isEqualToString:@"iPhone9,4"])    return @"iPhone 7 Plus (GSM)";
    if ([platform isEqualToString:@"iPhone10,1"])    return @"iPhone 8 (CDMA)";
    if ([platform isEqualToString:@"iPhone10,2"])    return @"iPhone 8 Plus (CDMA)";
    if ([platform isEqualToString:@"iPhone10,3"])    return @"iPhone X (CDMA)";
    if ([platform isEqualToString:@"iPhone10,4"])    return @"iPhone 8 (GSM)";
    if ([platform isEqualToString:@"iPhone10,5"])    return @"iPhone 8 Plus (GSM)";
    if ([platform isEqualToString:@"iPhone10,6"])    return @"iPhone X (GSM)";
    
    // iPad
    if ([platform isEqualToString:@"iPad1,1"])      return @"iPad 1";
    if ([platform isEqualToString:@"iPad2,1"])      return @"iPad 2 (WiFi)";
    if ([platform isEqualToString:@"iPad2,2"])      return @"iPad 2 (GSM)";
    if ([platform isEqualToString:@"iPad2,3"])      return @"iPad 2 (CDMA)";
    if ([platform isEqualToString:@"iPad2,4"])      return @"iPad 2 (Mid 2012)";
    if ([platform isEqualToString:@"iPad3,1"])      return @"iPad 3 (WiFi)";
    if ([platform isEqualToString:@"iPad3,2"])      return @"iPad 3 (CDMA)";
    if ([platform isEqualToString:@"iPad3,3"])      return @"iPad 3 (GSM)";
    if ([platform isEqualToString:@"iPad3,4"])      return @"iPad 4 (WiFi)";
    if ([platform isEqualToString:@"iPad3,5"])      return @"iPad 4 (GSM)";
    if ([platform isEqualToString:@"iPad3,6"])      return @"iPad 4 (Global)";
    
    // iPad Air
    if ([platform isEqualToString:@"iPad4,1"])      return @"iPad Air (WiFi)";
    if ([platform isEqualToString:@"iPad4,2"])      return @"iPad Air (Cellular)";
    if ([platform isEqualToString:@"iPad4,3"])      return @"iPad Air (China)";
    if ([platform isEqualToString:@"iPad5,3"])      return @"iPad Air 2 (WiFi)";
    if ([platform isEqualToString:@"iPad5,4"])      return @"iPad Air 2 (Cellular)";
    
    // iPad Mini
    if ([platform isEqualToString:@"iPad2,5"])      return @"iPad Mini (WiFi)";
    if ([platform isEqualToString:@"iPad2,6"])      return @"iPad Mini (GSM)";
    if ([platform isEqualToString:@"iPad2,7"])      return @"iPad Mini (Global)";
    if ([platform isEqualToString:@"iPad4,4"])      return @"iPad Mini 2 (WiFi)";
    if ([platform isEqualToString:@"iPad4,5"])      return @"iPad Mini 2 (Cellular)";
    if ([platform isEqualToString:@"iPad4,6"])      return @"iPad Mini 2 (China)";
    if ([platform isEqualToString:@"iPad4,7"])      return @"iPad Mini 3 (WiFi)";
    if ([platform isEqualToString:@"iPad4,8"])      return @"iPad Mini 3 (Cellular)";
    if ([platform isEqualToString:@"iPad4,9"])      return @"iPad Mini 3 (China)";
    if ([platform isEqualToString:@"iPad5,1"])      return @"iPad Mini 4 (WiFi)";
    if ([platform isEqualToString:@"iPad5,2"])      return @"iPad Mini 4 (Cellular)";
    
    // iPad Pro
    if ([platform isEqualToString:@"iPad6,3"])      return @"iPad Pro (9.7 inch/WiFi)";
    if ([platform isEqualToString:@"iPad6,4"])      return @"iPad Pro (9.7 inch/Cellular)";
    if ([platform isEqualToString:@"iPad6,7"])      return @"iPad Pro (12.9 inch/WiFi)";
    if ([platform isEqualToString:@"iPad6,8"])      return @"iPad Pro (12.9 inch/Cellular)";
    
    // iPod
    if ([platform isEqualToString:@"iPod1,1"])      return @"iPod Touch 1G";
    if ([platform isEqualToString:@"iPod2,1"])      return @"iPod Touch 2G";
    if ([platform isEqualToString:@"iPod3,1"])      return @"iPod Touch 3G";
    if ([platform isEqualToString:@"iPod4,1"])      return @"iPod Touch 4G";
    if ([platform isEqualToString:@"iPod5,1"])      return @"iPod Touch 5G";
    if ([platform isEqualToString:@"iPod7,1"])      return @"iPod Touch 6G";
    
    // Simulator
    if ([platform isEqualToString:@"i386"])         return @"Simulator";
    if ([platform isEqualToString:@"x86_64"])       return @"Simulator";
    
    return platform;
}

+ (BOOL)checkPlatformIsFourType{
    return [self checkString:[self platformString] containSubString:@"iPhone 4"];
}

+ (BOOL)checkPlatformIsFiveType{
    return [self checkString:[self platformString] containSubString:@"iPhone 5"];
}

+ (BOOL)checkPlatformIsSixType{
    BOOL bool1 = [[self platformString] isEqualToString:@"iPhone 6"];
    BOOL bool2 = [[self platformString] isEqualToString:@"iPhone 6s"];
    BOOL bool3 = [[self platformString] isEqualToString:@"iPhone SE"];
    BOOL bool4 = [[self platformString] isEqualToString:@"iPhone 7 (Global)"];
    BOOL bool5 = [[self platformString] isEqualToString:@"iPhone 7 (GSM)"];
    return bool1 || bool2 || bool3 || bool5 || bool4;
}

+ (BOOL)checkPlatformIsSixPlusType{
    BOOL bool1 = [[self platformString] isEqualToString:@"iPhone 6 Plus"];
    BOOL bool2 = [[self platformString] isEqualToString:@"iPhone 6s Plus"];
    BOOL bool4 = [[self platformString] isEqualToString:@"iPhone 7 Plus (Global)"];
    BOOL bool5 = [[self platformString] isEqualToString:@"iPhone 7 Plus (GSM)"];
    return bool1 || bool2 || bool4 || bool5;
}

+ (NSString *)stringFromOperatorType:(NSRAOperatorType)type {
    
    switch (type) {
        case NSRAOperatorTypeCNTT:
            return @"中国电信";
        case NSRAOperatorTypeCMCC:
            return @"中国移动";
            
        default:
            return @"未知";
    }
}

+ (NSString *)stringFromFSUControlType:(NSRAFSUControlType)type {
    
    switch (type) {
        case NSRAFSUControlTypeGJ:
            return @"智能光交";
        case NSRAFSUControlTypeWellLid:
            return @"智能井盖";
            
        default:
            return @"未知";
    }
}

+ (NSString *)logogramFromOperatorType:(NSRAOperatorType)type {
    
    switch (type) {
        case NSRAOperatorTypeCNTT:
            return @"cntt";
        case NSRAOperatorTypeCMCC:
            return @"cmcc";
            
        default:
            return @"null";
    }
}

+ (NSString *)formatCode:(NSString *)code {
    NSMutableArray *chars = [[NSMutableArray alloc] init];
    
    for (int i = 0, j = 0 ; i < [code length]; i++, j++) {
        [chars addObject:[NSNumber numberWithChar:[code characterAtIndex:i]]];
        if (j == 3) {
            j = -1;
            [chars addObject:[NSNumber numberWithChar:' ']];
            [chars addObject:[NSNumber numberWithChar:' ']];
        }
    }
    
    int length = (int)[chars count];
    char str[length];
    for (int i = 0; i < length; i++) {
        str[i] = [chars[i] charValue];
    }
    
    NSString *temp = [NSString stringWithUTF8String:str];
    return temp;
}

+ (BOOL)checkIsBarCodeValue:(NSString *)valueString {
    
    if (valueString.length == 15) {
        return YES;
    } else {
        return NO;
    }
}

+ (NSDate *)getDateAfterDay:(NSInteger)day hour:(NSInteger)hour minute:(NSInteger)minute second:(NSInteger)second{
    NSTimeInterval timeInterval = 24 * 60 * 60 * day + 60 * 60 * hour + 60 * minute * second;
    
    return [NSDate dateWithTimeInterval:(timeInterval) sinceDate:[NSDate date]];
}

+ (BOOL)requestIsSuccessful:(NSDictionary *)responseObject {
    if (responseObject && [[responseObject allKeys] containsObject:@"result"]) {
        return [responseObject[@"result"] boolValue];
    } else {
        return NO;
    }
}

@end
